import mockjs from "mockjs";

const data = mockjs.mock(
    {
    errno:0,
    message:'搜索成功',
        //随机10-20数据,前面有c是中文，否则是英文
        "data|1000-2000":[{
            'blog_id|+1':0,
            'article':'@ctitle(10,15)',
            'summary':'@cparagraph(4,6)',
            'click':'@integer(10,400)',  //文章点击量
            'author_id':'@cname(2,4)', //作者id
            'date':'@date()',  //文章发布时间
            'is_haspicture':'@boolean()',
            'img_href':'@image()'
        }],
});

const data1 = mockjs.mock({    
    errno:0,
    message:'点击成功',
})

mockjs.mock(/^http:\/\/192.168.3.22:8080\/search/,"post",(options)=>{
    return data
})

mockjs.mock(/^http:\/\/192.168.3.22:8080\/clickBlog/,"post",(options)=>{
    let sub = JSON.parse(options.body)
    
    console.log(sub.data.blog_id);
    if(data1.errno==0){
        data.data.some(u=>{
            if(u.blog_id===sub.data.blog_id){
                u.click++;
            }
        })
    }
    return data1
})





